<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/10/13
  Time: 下午 03:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form action="/AddStuServlet" method="post" >
  学号:<input type="text" name="stuNo"  value="">
  姓名:<input type="text" name="stuName"  value=""><br>
  密码:<input type="text"  name="loginPwd" placeholder="6位以上数字字母组合" value="">
  <span id="pwd"></span>
  <br>
  性别:<input type="radio" name="sex"  value="0">男
  <input type="radio" name="sex"  value="1">女<br>
  所属班级: <select name="gradeId">
  <option value="1">大一</option>
  <option  value="2">大二</option>
  <option  value="3">大三</option>
  <option  value="4">大四</option>
  <option  value="5">预科班</option>

</select><br>
  电话:<input type="text" name="phone" placeholder="11位数字" value="">
  <span id="phone"></span>
  <br>
  地址:<input type="text" name="address" value=""><br>
  出生日期:<input type="text" name="bornDate"  placeholder="yyyy-MM-dd" value="">
  <span id="bornDate"></span>
  <br>
  email:<input type="text" name="email"  placeholder="456@qq/163.com" value="">
  <span id="email"></span>
  <br>
  身份证号:<input type="text" name="identityCard" value=""><br>
  <input type="submit" value="提交">
</form>
  <script src="../js/jquery-3.6.0.min.js"></script>
<script>
  $(function (){
    $("input[name=loginPwd]").blur(function (){
      checkLoginPwd();
    })
    $("input[name=phone]").blur(function (){
      checkPhone();
    })
    $("input[name=bornDate]").blur(function (){
      checkBornDate();
    })
    $("input[name=email]").blur(function (){
      checkEmail();
    })
    $("form").submit(function (){
      if(!checkLoginPwd()){
        return false;
      }
      if(!checkBornDate()){
        return false;
      }
      if(!checkEmail()){
        return false;
      }
      if(!checkPhone()){
        return false;
      }
      return true;
    })
  })

  function  checkLoginPwd(){
    $("#pwd").text("");
    var pwd=$("input[name=loginPwd]").val();
    var reg=/^\w{6,}$/;
    if(!reg.exec(pwd)){
      $("#pwd").text("6位以上数字字母组合");
      return false;
    }
    return true;
  }

  function  checkPhone(){
    $("#phone").text("");
    var phone=$("input[name=phone]").val();
    var reg=/^(13|15|17)(\d){9}$/;
    if(!reg.exec(phone)){
      $("#phone").text("必须以13,15,17开头的11位数字");
      return false;
    }
    return true;
  }


  function  checkBornDate(){
    $("#bornDate").text("");
    var bornDate=$("input[name=bornDate]").val();
    var reg=/^\d{4}-([1-9]|1[0-2])-([1-9]|1\d|2\d|3[0-1])$/;
    if(!reg.exec(bornDate)){
      $("#bornDate").text("yyyy-MM-dd");
      return false;
    }
    return true;
  }

  function  checkEmail(){
    $("#email").text("");
    var email=$("input[name=email]").val();
    var reg=/^(\d){6,}[@](qq|163).(cn|com)$/;
    if(!reg.exec(email)){
      $("#email").text("34328@qq/163.com");
      return false;
    }
    return true;
  }
</script>
</body>
</html>
